package com.fanco.learn_datastruct_leetcode.designpattern.command;

/**
 * @author qiaowang 2022/2/17
 * 描述
 */
public class Client {
    public static void main(String[] args) {
        // 使用命令设计模式 完成 通过遥控器 对电灯的操作

        LightReceiver lightReceiver = new LightReceiver();

        // 创建电灯相关的开关
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        // 需要一个遥控器
        RemoteController remoteController = new RemoteController();

        // 给遥控器设置命令
        remoteController.setCommand(0,lightOnCommand,lightOffCommand);

        System.out.println("----------------");

        System.out.println("开灯");
        remoteController.onButtonWasPushed(0);

        System.out.println("关灯");
        remoteController.offButtonWasPushed(0);

        System.out.println("撤销按钮");
        remoteController.undoButtonWasPushed();

        TvReceiver tvReceiver = new TvReceiver();
        TvOnCommand tvOnCommand = new TvOnCommand(tvReceiver);
        TvOffCommand tvOffCommand = new TvOffCommand(tvReceiver);

        remoteController.setCommand(1, tvOnCommand, tvOffCommand);

        remoteController.onButtonWasPushed(1);
        remoteController.offButtonWasPushed(1);
    }
}
